using Microsoft.Extensions.Hosting;
using System.Threading;
using System.Threading.Tasks;

namespace Quant.Services
{
    public class TradeBackgroundService : BackgroundService
    {
        private readonly CoreEngine _engine;
        private TimeSpan CheckInterval = TimeSpan.FromSeconds(5);

        public TradeBackgroundService(CoreEngine engine)
        {
            _engine = engine;
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                await _engine.CheckAndTradeAsync();
                await Task.Delay(CheckInterval, stoppingToken);
            }
        }
    }
}